﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace JQueryWidget.WidgetFrame
{
    public class CMTVisionEditor:Telerik.Web.UI.RadEditor
    {
        public CMTVisionEditor()
            :base()
        {
            EnableResizeContentToControl = false;
        }

        public bool EnableResizeContentToControl
        { get; set; }

        public string ResizeContentToControlSelector
        { get; set; }

        public FooterMode FooterMode
        { get; set; }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();           
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e); 

            if (EnableResizeContentToControl)
            {
                if (!String.IsNullOrEmpty(ResizeContentToControlSelector))
                {
                    string contentFrameId = this.ClientID + "_contentIframe";
                    string scriptText = string.Format("Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function () {{$('#{0}').find('#{1}').height($('{2}').height());}});", ClientID, contentFrameId, ResizeContentToControlSelector).ToString();
                    ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID + "_ResizeContentToControl", scriptText, true);
                }
            }

            if (FooterMode == WidgetFrame.FooterMode.ShowOnFocus)
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID + "_wrapbottom", "<script type='text/javascript'>wrapBottomTablle();</script>", false);
            }
        }
    }

    public enum FooterMode
    {
        Default = 1,
        Floating = 2,
        PageTop = 4,
        ShowOnFocus = 8,
    }
}